﻿using System.Linq;
using Dolany.UtilityTool;
using Missbot.Common;
using Missbot.Core.Common;

namespace Missbot.AIModule.Schedulers.DailyVtuber
{
    /// <summary>
    /// Vtuber图片服务
    /// </summary>
    public class VtuberPicSvc : ISingleton
    {
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="VtuberName"></param>
        /// <param name="Url"></param>
        /// <param name="IsSensitive"></param>
        /// <returns></returns>
        public bool PicUpload(string VtuberName, string Url, bool IsSensitive = false)
        {
            var folders = Requestor.GetFolders();
            var folder = folders.FirstOrDefault(f => f.Name == VtuberName) ?? Requestor.CreateFolder(VtuberName); // 获取Vtuber对应的文件夹

            var file = FileUploader.PicUpload(folder.ID, Url, IsSensitive);
            if (file == null)
            {
                return false;
            }

            var model = new VtuberPicModel { VtuberName = VtuberName, FileID = file.ID, Url = file.Url };
            model.Insert();
            return true;
        }

        /// <summary>
        /// 获取随机图片
        /// </summary>
        /// <returns></returns>
        public VtuberPicModel RandPic()
        {
            return VtuberPicModelDA.GetByIndex(Rander.RandInt(50));
        }
    }
}